package com.java.demo.model;

/**
 * @author zhangwj
 * @date 2020/9/4 4:04 下午
 */
public class BuilderPattern {
    public static void main(String[] args) {
        Personal builder = new Personal.Builder("张三").getAge(10).build();
        System.out.println(builder);
    }
}


class Personal {

    private final int age;

    private final String name;

    private final short high;

    @Override
    public String toString() {
        return "Personal{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", high=" + high +
                '}';
    }

    public Personal(Builder builder) {
        this.age = builder.age;
        this.name = builder.name;
        this.high = builder.high;
    }

    static class Builder {
        private int age;

        private String name;

        private short high;

        public Builder(String name) {
            this.name = name;
        }

        public Builder getAge(int age) {
            this.age = age;
            return this;
        }

        public Builder getHigh(short high) {
            this.high = high;
            return this;
        }

        public Personal build() {
            return new Personal(this);
        }
    }


}